﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SMS.Entities.BaseClasses;
using System.Collections.Generic;
using SMS.Entities;
using System.Windows.Data;
using SMS.Common.Silverlight;
using System.ComponentModel;
using SMS.Controls.BranchSVC;
using SMS.Entities.Master;

namespace SMS.Model
{
    public class branchMasterModel 
    {
        ServiceProxy<BranchServiceClient> proxy = null;
        public event Action<int> OnSaveBranchCompleted;
        public event Action<System.Collections.ObjectModel.ObservableCollection<Branch>> OnSearchCompleted;
        public event Action<SMSException> OnServiceError;
        public branchMasterModel()
        {
            proxy = new ServiceProxy<BranchServiceClient>("Service/BranchService.svc");
            proxy.Client.SearchBranchCompleted += new EventHandler<SearchBranchCompletedEventArgs>(Client_SearchBranchCompleted);
            proxy.Client.SaveBranchCompleted += new EventHandler<SaveBranchCompletedEventArgs>(Client_SaveBranchCompleted);
        }

        void Client_SaveBranchCompleted(object sender, SaveBranchCompletedEventArgs e)
        {
            if (OnSaveBranchCompleted != null)
            {
                OnSaveBranchCompleted(e.Result);
            }
        }

        void Client_SearchBranchCompleted(object sender, SearchBranchCompletedEventArgs e)
        {
            if (OnSearchCompleted != null)
            {
                OnSearchCompleted(e.Result);
            }
        }

        public void SaveBranch(Branch branch)
        {
            proxy.Client.SaveBranchAsync(App.LoggedinUserName, branch);
        }

        public void SearchBranch(string searchText)
        {
            proxy.Client.SearchBranchAsync(App.LoggedinUserName, searchText);
        }
    }
}